package com.android.jingweiapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.jingweiapp.R;
import com.android.jingweiapp.bean.MailListBean;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by cuiwenrui-pc on 15/10/31.
 * 信箱反馈的Adapter
 */

public class MailAdapter extends BaseAdapter {

    private ViewHolder holder;
    private final LayoutInflater inflater;
    private final ArrayList<MailListBean.DataEntity> arrayList;

    public MailAdapter(ArrayList<MailListBean.DataEntity> arrayList, Context context) {
        this.inflater = LayoutInflater.from(context);
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        holder = null;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_mailinfo, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvId.setText(arrayList.get(position).getId());
        holder.tvStatus.setText(arrayList.get(position).getState());
        holder.tvTitle.setText(arrayList.get(position).getTitle());
        holder.tvTime.setText(arrayList.get(position).getTime());
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'item_mailinfo.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.tv_id)
        TextView tvId;
        @Bind(R.id.tv_status)
        TextView tvStatus;
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.tv_time)
        TextView tvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
